<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: Dean <zxxjjforever@163.com>
// +----------------------------------------------------------------------
namespace plugins\Dashboard;//Demo插件英文名，改成你的插件英文就行了

use cmf\lib\Plugin;
use think\Db;
class DashboardPlugin extends Plugin
{

    public $info = [
        'name'        => 'Dashboard',//Demo插件英文名，改成你的插件英文就行了
        'title'       => 'ZHL仪表盘',
        'description' => 'ZHL仪表盘',
        'status'      => 1,
        'author'      => 'zhl',
        'version'     => '1.0',
        'demo_url'    => 'http://demo.thinkcmf.com',
        'author_url'  => 'http://www.thinkcmf.com'
    ];

    public $hasAdmin = 0;//插件是否有后台管理界面

    // 插件安装
    public function install()
    {
        return true;//安装成功返回true，失败false
    }

    // 插件卸载
    public function uninstall()
    {
        return true;//卸载成功返回true，失败false
    }

    //实现的钩子方法
    public function adminDashboard($param)
    {
//        $yesterday=$this->yesterday();
//        $today=$this->today();
//        $yesterday_where['post_type']=1;
//        $yesterday_where['create_time']=['between',$yesterday];
//        $yesterday_news=Db::name('portal_post')->where($yesterday_where)->count();
//        $this->assign('yesterday_news',$yesterday_news);
//        $today_where['post_type']=1;
//        $today_where['create_time']=['between',$today];
//        $today_news=Db::name('portal_post')->where($today_where)->count();
//        $this->assign('today_news',$today_news);
//
//        $new_where['post_type']=1;
//        $new_count=Db::name('portal_post')->where($new_where)->count();
//        $this->assign('new_count',$new_count);
        //总订单
        $order_count=Db::name('order')->count();
        $this->assign('order_count',$order_count);
        //总店铺
        $store_count=Db::name('store')->count();
        $this->assign('store_count',$store_count);
        //总商品
        $goods_count=Db::name('goods')->count();
        $this->assign('goods_count',$goods_count);
        $user_count=Db::name('user')->count();
        $this->assign('user_count',$user_count);

        return [
            'width'  => 12,
            'view'   => $this->fetch('widget'),
            'plugin' => 'Dashboard'
        ];
    }

    function yesterday()
    {
        $yesterday = date('d') - 1;
        return [
            mktime(0, 0, 0, date('m'), $yesterday, date('Y')),
            mktime(23, 59, 59, date('m'), $yesterday, date('Y'))
        ];
    }
    function today()
    {
        $today = date('d') ;
        return [
            mktime(0, 0, 0, date('m'), $today, date('Y')),
            mktime(23, 59, 59, date('m'), $today, date('Y'))
        ];
    }

}